/**
 * sns指数-视频统计
 */
;
(function($, window, document, undefined) {
    var SNSVideoStatistic = function(el, opts) {
        this.el = el;
        this.defaults = {
            theme: 'macarons',
            chartOption: {
                calculable: true,
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    x: 'center',
                    y: '0',
                    data: ['评论总量', '评论留存率']
                },
                dataZoom: {
                    show: true,
                    realtime: true,
                    start: 0,
                    end: 100
                },

                xAxis: [{
                    type: 'category',
                    splitLine: {
                        show: false
                    },
                    data: []
                }],
                yAxis: [{
                    type: 'value'
                }, {
                    type: 'value'
                }],
                series: [{
                    name: '评论总量',
                    type: 'bar',
                    data: []
                }, {
                    name: '评论留存率',
                    yAxisIndex: 1,
                    type: 'line',
                    max: 100,
                    min: 0,
                    data: []
                }]
            }
        };
        this.options = $.extend({}, this.defaults, opts);
    }

    SNSVideoStatistic.prototype = {
        init: function() {
            var me = this,
                el = me.el;

            if (el.attr('data-initialized') == 'true') {
                return me;
            }

            me.initChart();
            me.bindEvents();


            el.attr('data-initialized', 'true');
            return me;
        },


        /**
         * [bindEvents description]
         * @return {[type]} [description]
         */
        bindEvents: function() {
            var me = this,
                el = me.el;

        },

        /**
         * 格式化数据
         * @param  {[type]} data [description]
         * @return {[type]}      [description]
         */
        formatData: function(originData) {
            var me = this,
                el = me.el,
                chartOption = me.options.chartOption;


            // 初始化series

            return chartOption;
        },

        initChart: function() {
            var me = this,
                el = me.el;

            comChart = echarts.init(el[0], me.options.theme);
            option = me.formatData(me.options.data);
            comChart.setOption(option);
        }
    }

    $.fn.SNSVideoStatistic = function(opts) {
        var me = this,
            el = me.el,
            comSNSVideoStatistic;

        // 如果没有被初始化过
        if (!(el && el.length && el.attr('data-initialized') != 'true')) {
            comSNSVideoStatistic = new SNSVideoStatistic(this, opts);
        }

        return comSNSVideoStatistic.init();
    }
})(jQuery, window, document);
